export const schema = {
    type: "page",
    title: "商品列表",
    body: {
        type: "crud",
        api: "get:/api/goods",
        columnsTogglable: false,
        filter: {
            title: "",
            submitText: "",
            panelClassName: 'm-b-none bg-gd no-border',
            bodyClassName: 'wrapper-sm',
            controls: [
                {
                    type: "text",
                    name: "keyword",
                    label: "商品查询",
                    placeholder: "商品名称"
                },
                {
                    type: "select",
                    name: "team_id",
                    label: "发布团队",
                    source: "/api/team/sug?auth_create_goods=1&_=$_",
                    clearable: true
                },

                {
                    type: "select",
                    name: "type",
                    label: "商品类型",
                    clearable: true,
                    options: [
                        {
                            label: "实物类",
                            value: 0
                        },
                        {
                            label: "优惠券",
                            value: 1
                        }
                    ]
                },

                {
                    type: "select",
                    name: "is_display",
                    label: "状态",
                    clearable: true,
                    options: [
                        {
                            label: "已上架",
                            value: 1
                        },
                        {
                            label: "已下架",
                            value: 0
                        }
                    ]
                },

                {
                    type: 'button-toolbar',
                    buttons: [

                        {
                            type: "submit",
                            label: "搜索",
                            primary: true
                        }
                    ]
                }

            ]
        },
        showHeader: false,
        columns: [
            {
                name: "id",
                label: "商品ID"
            },
            {
                name: "type",
                label: "商品类型",
                type: 'map',
                map: {
                    1: '优惠券',
                    0: '实物类'
                }

            },
            {
                name: "g_name",
                label: "商品名称",
                type: "tpl",
                width: 200,
                tpl: "<a data-link='/score_mall/goods/view/${id}'>${g_name}</a>"
            },
            {
                name: "org_id",
                label: "所属机构",
                type: "tpl",
                visibleOn: 'data.acl.can("org:view")',
                tpl: `<% if (data.acl.can("org:view")) { %>
                    <a data-link='/org/view/<%= data.org_info.id %>'><%= data.org_info.name %></a>
                    <% } else { %>
                        <span><%= data.org_info.name %></span>
                        <% } %>`
            },
            {
                name: "team_info.name",
                // visibleOn: "team_info.name",
                label: "发布团队"
            },
            {
                name: "price",
                label: "商品价格"
            },
            {
                name: "points",
                label: "消耗积分"
            },
            {
                name: "orders_num",
                label: "下单数"
            },
            {
                name: "success_orders",
                label: "完成订单数"
            },
            {
                name: "g_num",
                label: "库存"
            },
            // {
            //     name: "",
            //     label: "领取方式"
            // },


            // {
            //     name: "title",
            //     label: "标题",
            //     type: "tpl",
            //     tpl: "<a data-link='/news/edit/${id}'>${title}</a>"
            // },


            {
                name: "is_display",
                width: 80,
                label: "状态",
                type: "map",
                map: {
                    "0": '<span class="label label-default">已下架</span>',
                    "1": '<span class="label label-success">已上架</span>'
                }
            },

            {
                label: "操作",
                type: "operation",
                width: 180,
                buttons: [
                    {
                        type: "button",
                        size: "xs",
                        level: "info",
                        label: "编辑",
                        actionType: "link",
                        link: "/score_mall/goods/edit/${id}"
                    },

                    {
                        type: "button",
                        size: "xs",
                        label: "下架",
                        level: "warning",
                        confirmText: "确定要下架？",
                        actionType: "ajax",
                        api: "put:/api/goods/display/$id",
                        visibleOn: "data.is_display == 1"
                    },

                    {
                        type: "button",
                        size: "xs",
                        label: "上架",
                        level: "success",
                        confirmText: "确定要上架？",
                        actionType: "ajax",
                        api: "put:/api/goods/is_display/$id",
                        visibleOn: "data.is_display == 0"
                    },
                    {
                        type: "button",
                        size: "xs",
                        label: "置顶",
                        level: "primary",
                        actionType: "ajax",
                        api: "put:/api/goods/top/$id",
                        visibleOn: "data.is_recommend == 0 || data.is_recommend == null"
                    },
                    {
                        type: "button",
                        size: "xs",
                        level: "primary",
                        label: "取消置顶",
                        actionType: "ajax",
                        api: "put:/api/goods/down/$id",
                        visibleOn: "data.is_recommend == 1"
                    },
                ]
            }
        ]
    }
};
